package com.it.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@ComponentScan("com.it")
@EnableWebMvc  // 帮我们自动加上 handlerMapping、handlerAdapter、JSON转换器
public class springmvcConfig implements WebMvcConfigurer {

    // 注入拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 配置方案一：拦截全部请求
         */
        registry.addInterceptor(new SpringMvcIntercept());

        /**
         * 配置方案二：指定拦截地址
         *           任意一层  ** 任意多层
         * 【语法】：.addPathPatterns("/拦截路径");
         */
        registry.addInterceptor(new SpringMvcIntercept()).addPathPatterns("/inter/data2");


        /**
         * 配置方案三：排除拦截
         * 【语法】：excludePathPatterns("/排除路径")
         */
         SpringMvcIntercept intercept = new SpringMvcIntercept();
         InterceptorRegistration interceptor = registry.addInterceptor(intercept);
         // 表示排除拦截 /inter/data1
         interceptor.excludePathPatterns("/inter/data1");
    }
}
